﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace Data
{
	 	//LotteryDes
		public class LotteryDes
	{	
		/// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey= "id";
		/// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.LotteryDes model)
        {
            return new DataAccess().Add<Model.LotteryDes>(model, primaryKey);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.LotteryDes model)
        {
            return new DataAccess().Update<Model.LotteryDes>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.LotteryDes>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.LotteryDes GetModel(long Id)
        {
            return new DataAccess().Get<Model.LotteryDes>(Id, primaryKey);
        }
        public Model.LotteryDes GetModelByLotteryDesid(long LotteryDesid)
        {
            return new DataAccess().Get<Model.LotteryDes>(LotteryDesid, "LotteryDesid");
        }
        public Model.LotteryDes GetModelBysql(string sql)
        {
            return new DataAccess().Get<Model.LotteryDes>(sql);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.LotteryDes>(primaryKey);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.LotteryDes> GetPageList_Where(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {          
            string strWhere = GetSqlWhere(newsclassid);
            totalCount = new DataAccess().GetCount<Model.LotteryDes>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryDes>(PageIndex, PageSize, primaryKey, primaryKey+" asc", strWhere);
        }
        public DataTable GetPageDT_Where(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {
            string strWhere = GetSqlWhere(newsclassid);
            totalCount = new DataAccess().GetCount<Model.LotteryDes>(primaryKey, strWhere);
            return ConvertHelper<Model.LotteryDes>.ConvertToDT(new DataAccess().GetPage_List<Model.LotteryDes>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere));
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhere(long newsclassid)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (newsclassid>0)
            {
                sqlWhere.Append(" and type =" + newsclassid);
            }         
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.LotteryDes>(Ids, primaryKey);
        }
	}
}